package face.array;

/**
 * @author spf
 * @date 2024/8/13
 * @time 21:27
 */

import java.util.Arrays;
import java.util.Scanner;

/**
 * 二分查找
 */
public class BinarySerch {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        Arrays.sort(a);
        System.out.println(Arrays.toString(a));
        int serch = serch(a, 5);
        System.out.println(serch);
    }

    private static int serch(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;

        if (target < nums[left] || target > nums[right]) {
            return -1;
        }
        while (left <= right) {
            int mid = (left + right) >> 1;
            if (nums[mid] == target) {
                return mid;
            }
            if (nums[mid] < target) {
                left = mid + 1;
            }
            if (nums[mid] > target) {
                right = mid - 1;
            }
        }
        return -1;
    }

}
